package com.macro.mall.service.impl;

import java.util.List;
import java.util.Objects;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.macro.mall.mapper.BmsMuseumGroupMapper;
import com.macro.mall.model.BmsMuseumGroup;
import com.macro.mall.query.BmsMuseumGroupQuery;
import com.macro.mall.dto.BmsMuseumGroupParam;
import com.macro.mall.service.BmsMuseumGroupService;
import com.macro.mall.utils.AdminUtils;

@Service
public class BmsMuseumGroupServiceImpl implements BmsMuseumGroupService {

    @Autowired
    private BmsMuseumGroupMapper baseMapper;

    @Override
    public List<BmsMuseumGroup> findPage(BmsMuseumGroupQuery query) {
        Integer pageNum = query.getPageNum();
        Integer pageSize = query.getPageSize();
        if (Objects.nonNull(pageNum) && Objects.nonNull(pageSize)) {
            PageHelper.startPage(pageNum, pageSize);
        }
        List<BmsMuseumGroup> list = baseMapper.findList(query);
        return list;
    }

    @Override
    public List<BmsMuseumGroup> findList(BmsMuseumGroupQuery query) {
        return baseMapper.findList(query);
    }

    @Override
    public int create(BmsMuseumGroupParam BmsMuseumGroupParam) {
        BmsMuseumGroup BmsMuseumGroup = new BmsMuseumGroup();
        BeanUtils.copyProperties(BmsMuseumGroupParam, BmsMuseumGroup);
        AdminUtils.setCreation(BmsMuseumGroup);
        return baseMapper.insert(BmsMuseumGroup);
    }

    @Override
    public int update(BmsMuseumGroupParam param) {
        BmsMuseumGroup entity = baseMapper.getById(param.getId());
        BeanUtils.copyProperties(param, entity);
        AdminUtils.setEdition(entity);
        return baseMapper.updateById(entity);
    }

    @Override
    public BmsMuseumGroup getById(Long id) {
        return baseMapper.getById(id);
    }

    @Override
    public int delete(List<Long> ids) {
        return baseMapper.updateDeleteId(ids);
    }
}
